package me.skyun.androidarch.welcome;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.widget.ImageView;

import me.skyun.androidarch.R;
import me.skyun.androidarch.account.LoginActivity;
import me.skyun.androidarch.base.BaseActivity;

/**
 * Created by linyun on 16/11/15.
 */
public class SplashActivity extends BaseActivity {

    private ImageView mImageView;

    protected ImageView getImageView() {
        return mImageView;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_splash);
        mImageView = (ImageView) findViewById(R.id.splash_iv_image);

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                gotoNextActivity();
            }
        }, getSleepTime());
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addCategory(Intent.CATEGORY_HOME);
        startActivity(intent);
    }

    protected int getSleepTime() {
        return 1500;
    }

    public void gotoNextActivity() {
        Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
        startActivity(intent);
        finish();
    }
}
